<!doctype html>
<meta charset="utf-8">
<title>WebSQL: FTS3 Crash in bug 703507</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
'use strict';

for (let command of ['optimize', 'offsets', 'snippet']) {
  async_test(testCase => {
    const database = openDatabase(
        'Fts3CrashTest', '1.0', 'Database for FTS3 crash test', 1024 * 1024);
    assert_not_equals(database, null, 'openDatabase should not fail');

    database.transaction(testCase.step_func(transaction => {
      transaction.executeSql(
          'DROP TABLE IF EXISTS main;', [], () => {},
          testCase.unreached_func('Table drop should not fail'));
      transaction.executeSql(
          'CREATE VIRTUAL TABLE main USING FTS3(fts3table);', [], () => {},
          testCase.unreached_func('FTS3 table creation should not fail'));
      transaction.executeSql(
          "INSERT INTO main VALUES (x'0000000000000000');", [], () => {},
          testCase.unreached_func('FTS3 table insertion should not fail'));

      transaction.executeSql(
          `SELECT ${command}(fts3table) FROM main;`, [],
          testCase.unreached_func(`${command} should not succeed`),
          testCase.step_func_done());
    }));
  }, `${command} should error out when used with an FTS3 magic column`);
}

</script>
